#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    //设置字体样式
    QString fontName= "";
    int loadedFontID = QFontDatabase::addApplicationFont(":/image/res/_H_Helvetica.ttc");
    QStringList loadedFontFamilies = QFontDatabase::applicationFontFamilies(loadedFontID);
    qDebug()<<loadedFontFamilies;
    if(!loadedFontFamilies.empty())
        fontName = loadedFontFamilies.at(6);
    QFont ft(fontName);
    ft.setPixelSize(20);


//    TitleLabel = new QLabel(tr("负荷相校验装置"));
//    TitleLabel->setFont(ft);

    csLabel = new QLabel(tr("参数设定区"));
    csLabel->setFont(ft);
    putLabel = new QPushButton(tr("输出源式"));
    putLabel->setFont(ft);
    putLabel->setStyleSheet("border:0px;");
    getLabel = new QPushButton(tr("接受源式"));
    getLabel->setFont(ft);
    getLabel->setStyleSheet("border:0px;");
    putRadio = new QRadioButton;
    putRadio->setChecked(true);
    putRadio->setFixedSize(20,20);
    getRadio = new QRadioButton;
    getRadio->setFixedSize(20,20);
    grop1 = new QButtonGroup;
    grop1->addButton(putRadio);
    grop1->addButton(getRadio);

    VLabel = new QPushButton(tr("额定电压:"));
    VLabel->setFont(ft);
    VLabel->setStyleSheet("border:0px;");
    ILabel = new QPushButton(tr("额定电流:"));
    ILabel->setFont(ft);
    ILabel->setStyleSheet("border:0px;");
    VEdit = new QLineEdit;
    VEdit->setFixedSize(200,35);
    //VEdit->setStyleSheet("border-style: solid;");
    VEdit->setFont(ft);
    VEdit->setAlignment(Qt::AlignCenter);
    VEdit->installEventFilter(this);

    IEdit = new QLineEdit;
    IEdit->setFixedSize(200,35);
    IEdit->setFont(ft);
    IEdit->installEventFilter(this);
    IEdit->setAlignment(Qt::AlignCenter);
    //IEdit->setStyleSheet("border-style: solid;");

    VRadio = new QRadioButton;
    VRadio->setChecked(true);
    VRadio->setFixedSize(20,20);
    IRadio = new QRadioButton;
    IRadio->setFixedSize(20,20);
    grop2 = new QButtonGroup;
    grop2->addButton(VRadio);
    grop2->addButton(IRadio);
    VCom=new QComboBox();
    VCom->setFixedSize(70,35);
    VCom->addItem("V");
    VCom->addItem("/√3V");
    //VCom->setStyleSheet("border-style: solid;");
    //danwei1->setStyleSheet("color:red;");
    VCom->setFont(ft);

    workbfbV = new QLabel(tr("工作百分表:"));
    workbfbV->setFont(ft);
    workbfbI = new QLabel(tr("工作百分表:"));
    workbfbI->setFont(ft);
    bfbVEdit = new QLineEdit;
    bfbVEdit->setFixedSize(210,35);
    bfbVEdit->setFont(ft);
    bfbVEdit->installEventFilter(this);
    //bfbVEdit->setAlignment(Qt::AlignCenter);
    //bfbVEdit->setStyleSheet("border-style: solid;");

    bfbIEdit = new QLineEdit;
    bfbIEdit->setFixedSize(210,35);
    bfbIEdit->setFont(ft);
    bfbIEdit->installEventFilter(this);
    //bfbIEdit->setAlignment(Qt::AlignCenter);
    //bfbIEdit->setStyleSheet("border-style: solid;");

    rlLabel = new QLabel(tr("输出容量:"));
    rlLabel->setFont(ft);
    rlEdit = new QLineEdit;
    rlEdit->setFixedSize(200,35);
    rlEdit->setFont(ft);
    rlEdit->installEventFilter(this);
    //rlEdit->setAlignment(Qt::AlignCenter);
    //rlEdit->setStyleSheet("border-style: solid;");

    ysLabel = new QLabel(tr("功率因数: (cos"));
    ysLabel->setFont(ft);
    ysEdit1 = new QLineEdit;
    ysEdit1->setFixedSize(55,35);
    ysEdit1->setFont(ft);
    ysEdit1->installEventFilter(this);
    //ysEdit1->setAlignment(Qt::AlignCenter);
    //ysEdit1->setStyleSheet("border-style: solid;");
    ysEdit2 = new QLineEdit;
    ysEdit2->setFixedSize(63,35);
    ysEdit2->setFont(ft);
    ysEdit2->installEventFilter(this);
    //ysEdit2->setAlignment(Qt::AlignCenter);
    //ysEdit2->setStyleSheet("border-style: solid;");

    kjLabel = new QLabel(tr("快捷输出设定:"));
    kjLabel->setFont(ft);
    kj1 = new QLabel(tr("U = "));
    kj1->setFont(ft);
    kj2 = new QLabel(tr("Y ="));
    kj2->setFont(ft);
    kj3 = new QLabel(tr("I = "));
    kj3->setFont(ft);
    kj4 = new QLabel(tr("Z = "));
    kj4->setFont(ft);

    kj5 = new QLabel(tr("-j "));
    kj5->setFont(ft);
    kj6 = new QLabel(tr("+j"));
    kj6->setFont(ft);
    kj7 = new QLabel(tr(" (cos s)"));
    kj7->setFont(ft);
    kj8 = new QLabel(tr(" (Ω)"));
    kj8->setFont(ft);

    kjEdit1 = new QLineEdit;
    kjEdit1->setFixedSize(100,35);
    kjEdit1->setFont(ft);
   // kjEdit1->setAlignment(Qt::AlignCenter);
    //kjEdit1->setStyleSheet("border-style: solid;");
    kjEdit2 = new QLineEdit;
    kjEdit2->setFixedSize(100,35);
    kjEdit2->setFont(ft);
   // kjEdit2->setAlignment(Qt::AlignCenter);
    //kjEdit2->setStyleSheet("border-style: solid;");
    kjEdit3 = new QLineEdit;
    kjEdit3->setFixedSize(100,35);
    kjEdit3->setFont(ft);
    //kjEdit3->setAlignment(Qt::AlignCenter);
    //kjEdit1->setStyleSheet("border-style: solid;");
    kjEdit4 = new QLineEdit;
    kjEdit4->setFixedSize(100,35);
    kjEdit4->setFont(ft);
    //kjEdit4->setAlignment(Qt::AlignCenter);
    //kjEdit1->setStyleSheet("border-style: solid;");
    kjEdit5 = new QLineEdit;
    kjEdit5->setFixedSize(100,35);
    kjEdit5->setFont(ft);
    //kjEdit5->setAlignment(Qt::AlignCenter);
    //kjEdit1->setStyleSheet("border-style: solid;");
    kjEdit6 = new QLineEdit;
    kjEdit6->setFixedSize(100,35);
    kjEdit6->setFont(ft);
    //kjEdit6->setAlignment(Qt::AlignCenter);
    //kjEdit1->setStyleSheet("border-style: solid;");

    TestLabel = new QLabel(tr("测试结果:"));
    TestLabel->setFont(ft);
    Test1 = new QLabel(tr("U = "));
    Test1->setFont(ft);
    Test2 = new QLabel(tr("I = "));
    Test2->setFont(ft);
    Test3 = new QLabel(tr("Y = "));
    Test3->setFont(ft);
    Test4 = new QLabel(tr("-j "));
    Test4->setFont(ft);
    Test5 = new QLabel(tr("cosφ = "));
    Test5->setFont(ft);
    Test6 = new QLabel(tr("φ = "));
    Test6->setFont(ft);
    Test7= new QLabel(tr("Z = "));
    Test7->setFont(ft);
    Test8 = new QLabel(tr("+j"));
    Test8->setFont(ft);
    TestEdit1 = new QLineEdit;
    TestEdit1->setFixedSize(100,35);
    TestEdit1->setFont(ft);
    //TestEdit1->setAlignment(Qt::AlignCenter);
    //TestEdit1->setStyleSheet("border-style: solid;");
    TestEdit2 = new QLineEdit;
    TestEdit2->setFixedSize(100,35);
    TestEdit2->setFont(ft);
    //TestEdit2->setAlignment(Qt::AlignCenter);
    //TestEdit2->setStyleSheet("border-style: solid;");
    TestEdit3 = new QLineEdit;
    TestEdit3->setFixedSize(100,35);
    TestEdit3->setFont(ft);
    //TestEdit3->setAlignment(Qt::AlignCenter);
    //TestEdit3->setStyleSheet("border-style: solid;");
    TestEdit4 = new QLineEdit;
    TestEdit4->setFixedSize(100,35);
    TestEdit4->setFont(ft);
    //TestEdit4->setAlignment(Qt::AlignCenter);
    //TestEdit4->setStyleSheet("border-style: solid;");
    TestEdit5 = new QLineEdit;
    TestEdit5->setFixedSize(100,35);
    TestEdit5->setFont(ft);
    //TestEdit5->setAlignment(Qt::AlignCenter);
    //TestEdit5->setStyleSheet("border-style: solid;");
    TestEdit6 = new QLineEdit;
    TestEdit6->setFixedSize(100,35);
    TestEdit6->setFont(ft);
    //TestEdit6->setAlignment(Qt::AlignCenter);
    //TestEdit6->setStyleSheet("border-style: solid;");
    TestEdit7 = new QLineEdit;
    TestEdit7->setFixedSize(100,35);
    TestEdit7->setFont(ft);
    //TestEdit7->setAlignment(Qt::AlignCenter);
    //TestEdit7->setStyleSheet("border-style: solid;");
    TestEdit8 = new QLineEdit;
    TestEdit8->setFixedSize(100,35);
    TestEdit8->setFont(ft);
    //TestEdit8->setAlignment(Qt::AlignCenter);
    //TestEdit8->setStyleSheet("border-style: solid;");

    button1 =new myButton;
    button1->setText(tr("停止"));
    button1->setFont(ft);
    button1->setFixedSize(150,50);
    button2 =new myButton;
    button2->setText(tr("启动"));
    button2->setFont(ft);
    button2->setFixedSize(150,50);
  //////////////////////////////////////////////////////////////
  //水平线
    shuiping1 = new QLabel(tr(""));
    shuiping1->setFixedSize(950,2);
    shuiping1->setStyleSheet("background-color:black;");

    shuiping2 = new QLabel(tr(""));
    shuiping2->setFixedSize(950,2);
    shuiping2->setStyleSheet("background-color:black;");

    shuiping3 = new QLabel(tr(""));
    shuiping3->setFixedSize(950,2);
    shuiping3->setStyleSheet("background-color:black;");


  //单位定义
    danweiV1 = new QLabel(tr("V"));
    danweiV1->setFont(ft);
    danweiV2 = new QLabel(tr("V"));
    danweiV2->setFont(ft);
    danweiV3 = new QLabel(tr("V"));
    danweiV3->setFont(ft);

    danweibfb1 = new QLabel(tr("%"));
    danweibfb1->setFont(ft);
    danweibfb2 = new QLabel(tr("%"));
    danweibfb2->setFont(ft);

    danweiI1 = new QLabel(tr("A"));
    danweiI1->setFont(ft);
    danweiI2 = new QLabel(tr("A"));
    danweiI2->setFont(ft);
    danweiI3 = new QLabel(tr("A"));
    danweiI3->setFont(ft);

    danweiVA1 = new QLabel(tr("VA"));
    danweiVA1->setFont(ft);

    dengyu =new QLabel(tr("="));
    dengyu->setFont(ft);

    du1 = new QLabel(tr("°)"));
    du1->setFont(ft);
    du2 = new QLabel(tr("°"));
    du2->setFont(ft);

  //////////////////////////////////////////////////////////////

    QHBoxLayout *layout1 =new QHBoxLayout;
    //layout1->addStretch(1);
    layout1->addSpacing(100);
    layout1->addWidget(csLabel);
    layout1->addSpacing(200);
    layout1->addWidget(putRadio);
    layout1->addWidget(putLabel);
    layout1->addSpacing(200);
    layout1->addWidget(getRadio);
    layout1->addWidget(getLabel);
    layout1->addStretch(1);

    QHBoxLayout *layout2 = new QHBoxLayout;
    layout2->addStretch(1);
    layout2->addWidget(VRadio);
    layout2->addWidget(VLabel);
    layout2->addWidget(VEdit);
    layout2->addWidget(VCom);
    layout2->addSpacing(100);
    layout2->addWidget(workbfbV);
    layout2->addWidget(bfbVEdit);
    layout2->addWidget(danweibfb1);
    layout2->addStretch(1);
    QHBoxLayout *layout3 = new QHBoxLayout;
    layout3->addStretch(1);
    layout3->addWidget(IRadio);
    layout3->addWidget(ILabel);
    layout3->addWidget(IEdit);
    layout3->addWidget(danweiI1);
    layout3->addSpacing(155);
    layout3->addWidget(workbfbI);
    layout3->addWidget(bfbIEdit);
    layout3->addWidget(danweibfb2);
    layout3->addStretch(1);

    QHBoxLayout *layout4 = new QHBoxLayout;
    //layout4->addStretch(1);
    layout4->addSpacing(70);
    layout4->addWidget(rlLabel);
    layout4->addWidget(rlEdit);
    layout4->addWidget(danweiVA1);
    layout4->addSpacing(163);
    layout4->addWidget(ysLabel);
    layout4->addWidget(ysEdit1);
    layout4->addWidget(du1);
    //layout4->addSpacing(10);
    layout4->addWidget(dengyu);
    //layout4->addSpacing(10);
    layout4->addWidget(ysEdit2);
    layout4->addStretch(1);

    QHBoxLayout *layout5 = new QHBoxLayout;
    layout5->addSpacing(31);
    layout5->addWidget(kjLabel);
    layout5->addSpacing(55);
    layout5->addWidget(kj1);
    layout5->addWidget(kjEdit1);
    layout5->addWidget(danweiV2);
    layout5->addSpacing(150);
    layout5->addWidget(kj2);
    layout5->addWidget(kjEdit3);
    layout5->addWidget(kj5);
    layout5->addWidget(kjEdit4);
    layout5->addWidget(kj7);
    layout5->addStretch(1);
    QHBoxLayout *layout6 = new QHBoxLayout;
    layout6->addSpacing(226);
    layout6->addWidget(kj3);
    layout6->addWidget(kjEdit2);
    layout6->addWidget(danweiI2);
    layout6->addSpacing(143);
    layout6->addWidget(kj4);
    layout6->addWidget(kjEdit5);
    layout6->addWidget(kj6);
    layout6->addWidget(kjEdit6);
    layout6->addWidget(kj8);
    layout6->addStretch(1);

    QHBoxLayout *layout7 =new QHBoxLayout;
    layout7->addSpacing(71);
    layout7->addWidget(TestLabel);
    layout7->addSpacing(55);
    layout7->addWidget(Test1);
    layout7->addWidget(TestEdit1);
    layout7->addWidget(danweiV3);
    layout7->addSpacing(40);
    layout7->addWidget(Test2);
    layout7->addWidget(TestEdit2);
    layout7->addWidget(danweiI3);
    layout7->addSpacing(40);
    layout7->addWidget(Test3);
    layout7->addWidget(TestEdit3);
    layout7->addWidget(Test4);
    layout7->addWidget(TestEdit4);
    layout7->addStretch(1);

    QHBoxLayout *layout8 = new QHBoxLayout;
    layout8->addSpacing(186);
    layout8->addWidget(Test5);
    layout8->addWidget(TestEdit5);
    //layout8->addWidget(du1);
    layout8->addSpacing(53);
    layout8->addWidget(Test6);
    layout8->addWidget(TestEdit6);
    layout8->addWidget(du2);
    layout8->addSpacing(47);
    layout8->addWidget(Test7);
    layout8->addWidget(TestEdit7);
    layout8->addWidget(Test8);
    layout8->addWidget(TestEdit8);
    layout8->addStretch(1);

    QHBoxLayout *layout9 = new QHBoxLayout;
    layout9->addWidget(button1);
    layout9->addWidget(button2);



/////////////1111111111111///////////////////////////////
    QVBoxLayout *shadow1=new QVBoxLayout;
    shadow1->addStretch(1);
    shadow1->addLayout(layout1);
    shadow1->addSpacing(5);
    shadow1->addLayout(layout2);
    shadow1->addLayout(layout3);
    shadow1->addLayout(layout4);
    shadow1->addStretch(1);
    //阴影1
    QWidget *widgetTest1 = new QWidget;
    widgetTest1->setFixedSize(950,180);
    widgetTest1->setStyleSheet(".QWidget{background-color:#A9A9A9;border:1px solid #bbc;border-radius:5px;}");
    widgetTest1->setLayout(shadow1);
    QHBoxLayout *test1 =new QHBoxLayout;
    //test1->addStretch(1);
    test1->addSpacing(30);
    test1->addWidget(widgetTest1);
    test1->addStretch(1);

/////////////2222222222222///////////////////////////////
    QVBoxLayout *shadow2=new QVBoxLayout;
    shadow2->addLayout(layout5);
    shadow2->addLayout(layout6);
    //阴影1
    QWidget *widgetTest2 = new QWidget;
    widgetTest2->setFixedSize(950,92);
    widgetTest2->setStyleSheet(".QWidget{background-color:#A9A9A9;border:1px solid #bbc;border-radius:5px;}");
    widgetTest2->setLayout(shadow2);
    QHBoxLayout *test2 =new QHBoxLayout;
    //test1->addStretch(1);
    test2->addSpacing(30);
    test2->addWidget(widgetTest2);
    test2->addStretch(1);

///////////3333333333333/////////////////////////////////////

    QVBoxLayout *shadow3=new QVBoxLayout;
    shadow3->addLayout(layout7);
    shadow3->addLayout(layout8);
    //阴影1
    QWidget *widgetTest3 = new QWidget;
    widgetTest3->setFixedSize(950,92);
    widgetTest3->setStyleSheet(".QWidget{background-color:#A9A9A9;border:1px solid #bbc;border-radius:5px;}");
    widgetTest3->setLayout(shadow3);
    QHBoxLayout *test3 =new QHBoxLayout;
    //test1->addStretch(1);
    test3->addSpacing(30);
    test3->addWidget(widgetTest3);
    test3->addStretch(1);

    QHBoxLayout *test4 =new QHBoxLayout;
    test4->addSpacing(30);
    test4->addWidget(shuiping1);
    test4->addStretch(1);
    QHBoxLayout *test44 =new QHBoxLayout;
    test44->addSpacing(30);
    test44->addWidget(shuiping2);
    test44->addStretch(1);
    QHBoxLayout *test444 =new QHBoxLayout;
    test444->addSpacing(30);
    test444->addWidget(shuiping3);
    test444->addStretch(1);

    QVBoxLayout *main=new QVBoxLayout;
    main->addLayout(test1);
    main->addLayout(test4);//水平线
    main->addLayout(test2);
    main->addLayout(test44);
    main->addLayout(test3);
    main->addLayout(test444);
    main->addLayout(layout9);
    setLayout(main);
    theKeyBoard = new Dialog(this);

    connect(putLabel,SIGNAL(clicked()),this,SLOT(state1()));
    connect(getLabel,SIGNAL(clicked()),this,SLOT(state2()));

    connect(VLabel,SIGNAL(clicked()),this,SLOT(V_clicked()));
    connect(ILabel,SIGNAL(clicked()),this,SLOT(I_clicked()));
    connect(VRadio,SIGNAL(clicked()),this,SLOT(V_clicked()));
    connect(IRadio,SIGNAL(clicked()),this,SLOT(I_clicked()));

    connect(button1,SIGNAL(clicked(QString)),this,SLOT(stop_clicked()));
    connect(button2,SIGNAL(clicked(QString)),this,SLOT(start_clicked()));

    widgetInfo = new QWidget(this);
    //widgetInfo->setStyleSheet(".QWidget{background-color:rgb(204,102,0);border-radius:15px;}");
    //    widgetInfo->setStyleSheet(".QWidget{background-color:#666;border-radius:15px;}");
    widgetInfo->setStyleSheet(".QWidget{background-color:qColor(250,250,0,150);border-radius:15px;}");
    labInfo = new QLabel("欢迎使用...");
    labInfo->setStyleSheet("color:yellow;font:22px;font-weight:bold;");
    labInfo->setFixedWidth(400);
    labInfo->setAlignment(Qt::AlignCenter);

    QVBoxLayout *layoutInfo = new QVBoxLayout;
    layoutInfo->setAlignment(Qt::AlignCenter);
    layoutInfo->addWidget(labInfo);

    widgetInfo->setLayout(layoutInfo);
    widgetInfo->setFixedSize(450,100);
    widgetInfo->move(280,80);

    QTimer::singleShot(1000, this, SLOT(widgetInfoHide()));
}
void Widget::stop_clicked()
{
    qDebug()<<"stop";
}
void Widget::start_clicked()
{
    qDebug()<<"start";
}

void Widget::V_clicked()
{
    VRadio->setChecked(true);
    ILabel->setStyleSheet("color:#bbb;border:0px;");
    IEdit->setEnabled(false);
    danweiI1->setStyleSheet("color:#bbb;border:0px;");
    workbfbI->setStyleSheet("color:#bbb;border:0px;");
    bfbIEdit->setEnabled(false);
    danweibfb2->setStyleSheet("color:#bbb;border:0px;");

    VLabel->setStyleSheet("color:black;border:0px;");
    VEdit->setEnabled(true);
    VCom->setEnabled(true);
    workbfbV->setStyleSheet("color:black;border:0px;");
    bfbVEdit->setEnabled(true);
    danweibfb1->setStyleSheet("color:black;border:0px;");
}
void Widget::I_clicked()
{
    IRadio->setChecked(true);
    ILabel->setStyleSheet("color:black;border:0px;");
    IEdit->setEnabled(true);
    danweiI1->setStyleSheet("color:black;border:0px;");
    workbfbI->setStyleSheet("color:black;border:0px;");
    bfbIEdit->setEnabled(true);
    danweibfb2->setStyleSheet("color:black;border:0px;");

    VLabel->setStyleSheet("color:#bbb;border:0px;");
    VEdit->setEnabled(false);
    VCom->setEnabled(false);
    workbfbV->setStyleSheet("color:#bbb;border:0px;");
    bfbVEdit->setEnabled(false);
    danweibfb1->setStyleSheet("color:#bbb;border:0px;");
}
bool Widget::eventFilter(QObject *watched, QEvent *e)
{
    if(watched == VEdit)
    {
        if(e->type() == QEvent::FocusIn)
        {
            theKeyBoard->setCurrentActive(VEdit);
            qDebug()<<"VEdit: keyBoard show()";
        }
        else if(e->type() == QEvent::FocusOut)
        {
            theKeyBoard->hide();
        }
    }
    if(watched == IEdit)
    {
        if(e->type() == QEvent::FocusIn)
        {
            theKeyBoard->setCurrentActive(IEdit);
            qDebug()<<"IEdit: keyBoard show()";
        }
        else if(e->type() == QEvent::FocusOut)
        {
            theKeyBoard->hide();
        }
    }
    if(watched == bfbVEdit)
    {
        if(e->type() == QEvent::FocusIn)
        {
            theKeyBoard->setCurrentActive(bfbVEdit);
            qDebug()<<"bfbVEdit: keyBoard show()";
        }
        else if(e->type() == QEvent::FocusOut)
        {
            theKeyBoard->hide();
        }
    }
    if(watched == bfbIEdit)
    {
        if(e->type() == QEvent::FocusIn)
        {
            theKeyBoard->setCurrentActive(bfbIEdit);
            qDebug()<<"bfbIEdit: keyBoard show()";
        }
        else if(e->type() == QEvent::FocusOut)
        {
            theKeyBoard->hide();
        }
    }
    if(watched == rlEdit)
    {
        if(e->type() == QEvent::FocusIn)
        {
            theKeyBoard->setCurrentActive(rlEdit);
            qDebug()<<"rlEdit: keyBoard show()";
        }
        else if(e->type() == QEvent::FocusOut)
        {
            theKeyBoard->hide();
        }
    }
    if(watched == ysEdit1)
    {
        if(e->type() == QEvent::FocusIn)
        {
            theKeyBoard->setCurrentActive(ysEdit1);
            qDebug()<<"ysedit1: keyBoard show()";
        }
        else if(e->type() == QEvent::FocusOut)
        {
            theKeyBoard->hide();

//            double tmpCos = ysEdit1->text().toDouble();
//            tmpCos = tmpCos * PI / 180;
//            tmpCos = cos(tmpCos);
//            ysEdit2->setText(QString::number(tmpCos,'f',2));
            double tmpCos = ysEdit1->text().toDouble();
            tmpCos = tmpCos * PI / 180;
            if(tmpCos < 0)
            {
                tmpCos = cos(tmpCos);
                ysEdit2->setText(QString::number(tmpCos,'f',2)+"C");
            }
            else
            {
                tmpCos = cos(tmpCos);
                ysEdit2->setText(QString::number(tmpCos,'f',2)+"L");
            }
        }
    }
    if(watched == ysEdit2)
    {
        if(e->type() == QEvent::FocusIn)
        {
            theKeyBoard->setCurrentActive(ysEdit2);
            qDebug()<<"ysedit2: keyBoard show()";
        }
        else if(e->type() == QEvent::FocusOut)
        {
            theKeyBoard->hide();

            QString tmpStr = ysEdit2->text();

            double tmpAngle = 1;

            tmpStr = tmpStr.mid(tmpStr.length() -1);

            if(tmpStr == "L" || tmpStr == "l")
            {
                tmpStr = ysEdit2->text();
                tmpStr = tmpStr.mid(0,tmpStr.length()-1);

                qDebug()<<tmpStr;
            }
            else if(tmpStr == "C" || tmpStr == "c")
            {
                tmpStr = ysEdit2->text();
                tmpStr = tmpStr.mid(0,tmpStr.length()-1);

                tmpAngle = -1;

                qDebug()<<tmpStr;
            }
            else
            {
                tmpStr = ysEdit2->text();
            }

            double tmpArcCos = tmpStr.toDouble();

            if(tmpArcCos <= 1
                    && tmpArcCos >= -1)
            {
                tmpAngle *= acos(tmpArcCos);
                tmpAngle = tmpAngle * 180 /PI;

                ysEdit1->setText(QString::number(tmpAngle,'f',1));
            }
            else
            {
                ysEdit1->setText("err");
            }
//            QString tmpStr = ysEdit2->text();

//            tmpStr = tmpStr.mid(tmpStr.length() -1);

//            if(tmpStr == "L")
//            {
//                tmpStr = ysEdit2->text();
//                tmpStr = tmpStr.mid(0,tmpStr.length()-1);

//                qDebug()<<tmpStr;
//            }
//            else if(tmpStr == "C")
//            {
//                tmpStr = ysEdit2->text();
//                tmpStr = tmpStr.mid(0,tmpStr.length()-1);
//                tmpStr = "-" + tmpStr;

//                qDebug()<<tmpStr;
//            }
//            else
//            {
//                tmpStr = ysEdit2->text();
//            }

//            double tmpArcCos = tmpStr.toDouble();

//            if(tmpArcCos <= 1
//                    && tmpArcCos >= -1)
//            {
//                tmpArcCos = acos(tmpArcCos);
//                tmpArcCos = tmpArcCos * 180 /PI;

//                ysEdit1->setText(QString::number(tmpArcCos,'f',1));
//            }
//            else
//            {
//                ysEdit1->setText("err");
//            }

        }
    }
    return QWidget::eventFilter(watched, e);
}
Widget::~Widget()
{
    
}
